﻿@model CERT.Models.LoginModel
@{
    ViewBag.Title = "CERT";
}
@functions{
    public string GetAntiForgeryToken()
    {
        string cookieToken, formToken;
        AntiForgery.GetTokens(null, out cookieToken, out formToken);
        return cookieToken + ":" + formToken;
    }
}

<div id="main-content" data-ng-app="app" >
    @if (@User.Identity.IsAuthenticated)
    {
        <div class="navbar navbar-inverse navbar-fixed-top" id="navbar">
           <div class="navbar-header">
          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">CERT</a>
        </div>
                    <div class="navbar-collapse collapse" >
                        <ul class="nav navbar-nav">
                            <li class="active"><a id="home" href="/">Home</a></li>
                            <li><a id="incident" href="#/Incidents">Incidents</a></li>
                            <li><a id="team" href="#/Teams">Teams</a></li>
                            <li class="dropdown">
                            <a  class="dropdown-toggle" href="#" data-toggle="dropdown">Administration <b class="caret"></b></a>
                            
                                <ul class="dropdown-menu">
                                    <!-- couldn't get this easily into configuration so used .net for menu -->
                                    @if (@User.IsInRole("Administrator"))
                                    {
                                        <li><a href="#/Admin/hazard">Hazards</a></li>
                                        <li><a href="#/Admin/team role">Team Role</a></li>
                                        <li><a href="#/Admin/location">Location</a></li>
                                        <li><a href="#/Admin/location status">Location Status</a></li>
                                        <li><a href="#/Admin/gender">Gender</a></li>
                                        <li><a href="#/Admin/age range">Age Range</a></li>
                                        <li><a href="#/Admin/victim status">Victim Status</a></li>
                                        <li class="divider"></li>
                                    }
                                    <li class="nav-header">Other</li>
                                    <li><a href="/">Home</a></li>
                                    <li><a href="#/About">About</a></li>
                                </ul>
                            
                            <li>@Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { @class = "btn btn-inverse username", title = "Manage", tooltip = "Manage" })</li>
                            <li>
                                <a id="logOff" class="btn btn-inverse" onclick="logOff()">Log off</a>
                            </li>

                        </ul>
                    </div>
                </div>
    
        <div data-ng-view></div> <!-- The SPA Views go here -->   
    }
    else
    {
        <div id="openModal" >
            
            @{
                Html.RenderAction("GetLoginDialog", "Home");
    }
    
            
            </div>
      
        
    }
</div>

@if (@User.Identity.IsAuthenticated)
{
    <input id="antiForgeryToken" type="hidden" value="@GetAntiForgeryToken()" />      
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
    <script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
    
    @section scripts {
        @Scripts.Render("~/js/angular")
        @Scripts.Render("~/js/app")
    }
    
    <script>
        function logOff() {

            $.ajax({
                url: '@Url.Action("LogOff", "Account")',
                type: "POST",
                async: true,
                dataType: "json",
                data: $('antiForgeryToken').serialize(),
                success: function () {
                    location.reload();
                    window.location.href = window.location.href;

                    // process result
                },
                error: function (request, status, error) {
                    // process error message
                    location.reload();
                }
            });
          

        }

@*        function Authenticate() {

            $.ajax({
                url: '@Url.Actiononload="Authenticate()" onfocus="Authenticate()" ("GetLoginDialog", "Account")',
                type: "POST",
                async: true,
                dataType: "json",
                data: $('antiForgeryToken').serialize(),
                success: function (data) {
                    // process result
                },
                error: function (request, status, error) {
                    // process error message
                }
            });


        }*@


    </script>
    
    
}